'use strict'

define([ 'jquery', 'bootstrap', 'select2', 'shiftform', 'validate',
        'validate.en','datetimepicker' ], function($) {
    return {
        init : function() {
            this.initCreate();
        },
        initCreate : function() {
            
            $(document).find('form[data-validate="true"]').bt_validate();
            
            $('#assessorUploadBtn').click(function(){
                return $("#assessorFile").click();
            });
            
            $('select[name="delegateOwner"]').select2({
              theme: "classic",
              placeholder : 'Delegate Owner',
              minimumResultsForSearch : -1,
              allowClear : true,
            });
            
            $('select[name="assessorOwner"]').select2({
              theme: "classic",
              placeholder : 'Accessor Owner',
              minimumResultsForSearch : -1,
              allowClear : true,
            });
            
           $('.date').datetimepicker({
              format: 'yyyy-mm-dd',
              autoclose: true,
              language: 'zh-CN',
              todayBtn: 'linked',
              startDate: '${today}',
              todayHighlight: true,
              pickerPosition: 'bottom-right',
              minView: 'month'
            });
           
           $('.start-date').on('changeDate', function(e){
               var beginDate = new Date($("input[name='startDate']").val());
               var ms = 2 * (1000 * 60 * 60 *24);
               var endDate = new Date(beginDate.getTime()+ms);
               var endDateString = endDate.yyyymmdd("-");
               $('.end-date').val(endDateString);
          });
           
           $('.end-date').on('changeDate', function(e){
               var endDate = new Date($("input[name='endDate']").val());
               var ms = 2 * (1000 * 60 * 60 *24);
               var beginDate = new Date(endDate.getTime()-ms);
               var beginDateString = beginDate.yyyymmdd("-");
               $('.start-date').val(beginDateString);
               
          });
           
           $('form[data-validate="true"]').bt_validate()  //bind validate
        }
        
    }
})
